<template>
  <div class="navBar" @click="showDrawer" :style="view?'border: none !important;background-color: '+props.backColor+';':'cursor: pointer;background-color: '+props.backColor+';'">
    <van-nav-bar
      :title="props.title"
      :right-text="props.rightText"
      :border="props.border"
    >
      <template slot="left">
        <div class="acea-row row-middle" :style="'color:'+props.leftTextColor+';'" >
          <van-icon name="arrow-left" v-if="props.leftArrow" :color="props.leftTextColor" class="left-icon" />
          {{props.leftText}}
        </div>
      </template>
    </van-nav-bar>
    <drawer :attr="list.attr" :show.sync="show" @change="editAttr" :index="list.index" />
  </div>
</template>

<script>
import drawer from "../drawer"
import changeAttr from '@/utils/changeAttr.js'
import changeViewAttr from '@/utils/changeViewAttr.js'

export default {
  components:{
    drawer
  },
  name:"navBar",
  props:{
    list:{
      type:Object,
    },
    view:{
      type:Boolean,
      default:false
    }
  },
  data() {
    return {
      show:false,
      props:{},
      changeAttr,
    }
  },
  created() {
    this.editAttr()
  },
  methods: {
    showDrawer(){
      if(!this.view){
        this.show = true
      }
    },
    editAttr(){
      if(this.view){
        this.props = changeViewAttr(this.list.attr,this.list.index)
      }else{
        this.props = changeAttr(this.list.attr,this.list.index)
      }
    }
  },
}
</script>

<style scoped>
  .navBar{
    box-sizing: border-box;
    border: 1px dashed transparent;
  }
  .navBar:hover{
    border: 1px dashed #1989fa;
  }
  .navBar >>> .left-icon{
    margin-right: 5px;
  }
  .navBar >>> .van-nav-bar{
    background-color: transparent;
  }
</style>